package 题目集.打印题;

/**
 * https://www.dotcpp.com/oj/contest6308_problem9.html
 */

import java.util.Scanner;

public class ch01_旋转90度 {
    static int n, m;
    static int[][] origin;
    static int[][] result;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        origin = new int[n][m];
        result = new int[m][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                origin[i][j] = sc.nextInt();
            }
        }
        int lx = 0, ly = 0;
        int rx = n - 1, ry = m - 1;
        while (lx <= rx && ly <= ry) {
            rotate(lx, ly, rx, ry);
            lx++;
            ly++;
            rx--;
            ry--;
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(result[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static void rotate(int lx, int ly, int rx, int ry) {
        int sx = ly, sy = n - lx-1;    //旋转后的坐标
        for (int i = ly; i < ry; i++) {   //顶部
            result[sx][sy] = origin[lx][i];
            sx++;
        }

        sx=ry; sy=n-lx-1;
        for (int i = lx; i < rx; i++) {   //右侧
            result[sx][sy] = origin[i][ry];
            sy--;
        }
        sx=ry; sy=n-rx-1;
        for (int i = ry; i > ly; i--) {   //底部
            result[sx][sy] = origin[rx][i];
            sx--;
        }
        sx=ly; sy=n-rx-1;
        for (int i = rx; i > lx; i--) {   //左侧
            result[sx][sy] = origin[i][ly];
            sy++;
        }
    }
}
